<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			//案例1		
			// var sum = 0;
			// var average = 0;
			// var arr1 = [2, 6, 1, 7, 4];
			// for (i = 0; i < arr1.length; i++) {
			// 	sum = sum + arr1[i];
			// }
			// average = sum / arr1.length;
			// console.log('和为' + sum);
			// console.log('平均值为' + average);

			// //案例2 求数组最大值
			// var arr = [2, 6, 1, 77, 52, 25, 7];
			// var max = arr[0];
			// for (i = 1; i < arr.length; i++) {
			// 	if (arr[i] > max) {
			// 		max = arr[i];
			// 	}
			// }
			// console.log('最大值为' + max);

			//案例3 数组转换为分隔字符串
			var arr = ['red', 'green', 'blue', 'pink'];
			var str = '';
			var sep = '!';
			for (var i = 0; i < arr.length; i++) {
				str += arr[i] + sep;
			}
			console.log(str);

			//案例4 数组存值
			var arr = [];
			for (i = 0; i < 100; i++) {
				arr[i] = i + 1;
			}
			console.log(arr);

			//案例5 筛选数组 追加新数组  方法1
			var arr1 = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
			var arr2 = [];
			var j = 0;
			for (i = 0; i < arr1.length; i++) {
				if (arr1[i] >= 10) {
					arr2[j] = arr1[i];
					j++;
				}
			}
			console.log(arr2);

			//案例6 筛选数组 追加新数组  方法2
			var arr1 = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
			var newArr = [];
			var j = 0;
			for (i = 0; i < arr1.length; i++) {
				if (arr1[i] >= 10) {
					newArr[newArr.length] = arr1[i];
				}
			}
			console.log(newArr);

			//案例7 数组去重 方法1
			var arr = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
			var arr2 = [];
			for (i = 0; i < arr.length; i++) {
				if (arr[i] !== 0) {
					arr2[arr2.length] = arr[i];
					j++;
				}
			}
			console.log(arr2);

			//案例8 数组去重 方法2
			var arr = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
			var j = 0;
			for (i = 0; i < arr.length; i++) {
				if (arr[i] !== 0) {
					arr2[j] = arr[i];
					j++;
				}
			}
			console.log(arr2);

			//案例9 翻转数组 方法1
			var arr = ['red', 'green', 'blue', 'pink', 'purple'];
			var arr2 = [];
			for (i = arr.length - 1; i >= 0; i--) {
				arr2[arr2.length] = arr[i]
			}
			console.log(arr2);

			//翻转数组 方法2
			var arr = ['red', 'green', 'blue', 'pink', 'purple'];
			var j = 0;
			for (i = arr.length - 1; i >= 0; i--) {
				arr2[j] = arr[i];
				j++;
			}
			console.log(arr2);
			
		</script>
	</head>

	<body>
	</body>

</html>
